package edu.gatech.cs2340.JUnit;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

import edu.gatech.cs2340.OregonTrail.Item;
import edu.gatech.cs2340.OregonTrail.PlayerInventory;

public class TestInventory {

	/**
	  * @Author Joshua Roberts
	  *
	  * This tests an addidition of a singular item to an instnace of playerInventory.
	  */
	@Test
	public void testAddSingular() {
		PlayerInventory inv = new PlayerInventory(new HashMap<Item, Integer>(), null);
		Item testItem = new Item();
		testItem.setItemName("test");
		testItem.setBaseCost(0);
		testItem.setWeight(5);
		inv.addItem(testItem);
		assertTrue(inv.getStock().containsKey(testItem));
		assertEquals(5, inv.getCurrentWeight());
	}
	
	/**
	  * @Author Tyler Johnston
	  *
	  * This tests adding more than one of an item to playerInventory.
	  */
	@Test
	public void testAddMult(){
		PlayerInventory inv = new PlayerInventory(new HashMap<Item, Integer>(), null);
		Item testItem = new Item();
		testItem.setItemName("test");
		testItem.setBaseCost(0);
		testItem.setWeight(5);
		inv.addItem(testItem, 5);
		assertEquals(new Integer(5), inv.getStock().get(testItem));
		assertEquals(25, inv.getCurrentWeight());
	}
	
	/**
	  * @Author Won Taek Chung
	  *
	  * This tests the removal of an object from playerInventory.
	  */
	@Test
	public void testRemoveSingular(){
		Map<Item, Integer> invItems = new HashMap<Item, Integer>();
		Item testItem = new Item();
		testItem.setItemName("test");
		testItem.setWeight(5);
		testItem.setBaseCost(5);
		invItems.put(testItem, 5);
		PlayerInventory inv = new PlayerInventory(invItems, null);
		assertTrue(inv.removeItem(testItem));
		assertEquals(20, inv.getCurrentWeight());
	}
	
	/**
	  * @Author Tyler Johnston
	  *
	  * This tests the removal of more than one of an item from playerInventory.
	  */
	@Test
	public void testRemoveMult(){
		Map<Item, Integer> invItems = new HashMap<Item, Integer>();
		Item testItem = new Item();
		testItem.setItemName("test");
		testItem.setWeight(5);
		testItem.setBaseCost(5);
		invItems.put(testItem, 5);
		PlayerInventory inv = new PlayerInventory(invItems, null);
		assertTrue(inv.removeItem(testItem, 5));
		assertEquals(0, inv.getCurrentWeight());
	}
	

}
